# Maintainer: Antonio Rojas <arojas@archlinux.org>

pkgname=libappimage
pkgver=1.0.4.5
_pkgver=1.0.4-5
pkgrel=5
pkgdesc='Reference implementation of the AppImage specification'
arch=(loong64 x86_64)
url='https://appimage.org/'
license=(GPL)
depends=(libarchive squashfuse boost-libs librsvg)
makedepends=(cmake wget vim desktop-file-utils boost xdg-utils-cxx)
source=(https://github.com/AppImage/libappimage/archive/v$_pkgver/$pkgname-$_pkgver.tar.gz
        https://github.com/AppImageCommunity/libappimage/commit/1e0515b2.patch)
sha256sums=('2c4e18860a790c5959da6eb064cbd07f165fe6a9b15989491a3a3f176d06af31'
            'd82b2519ba25a6a8a7743cc738a8c8e61cd49cfaca134741024a32f6cc5007ac')

prepare() {
  patch -d $pkgname-$_pkgver -p1 < 1e0515b2.patch # Fix build with GCC 13
}

build() {
  cmake -B build -S $pkgname-$_pkgver \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_C_FLAGS="$CFLAGS -ffat-lto-objects" \
    -DUSE_SYSTEM_XZ=ON \
    -DUSE_SYSTEM_SQUASHFUSE=ON \
    -DUSE_SYSTEM_LIBARCHIVE=ON \
    -DUSE_SYSTEM_BOOST=ON \
    -DUSE_SYSTEM_XDGUTILS=ON \
    -DBUILD_TESTING=OFF
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
}
